<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>选择应用</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/webui/style/admin.css" media="all">
    <link rel="stylesheet" href="/webui/style/login.css" media="all">
</head>
<body class="layui-layout-body">

<%-include("./base/head.ejs")%>

<div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-select" style="display: none;">

    <div class="layadmin-user-login-main">
        <div class="layadmin-user-login-box layadmin-user-login-header">
            <p>选择你准备登入的应用</p>
        </div>
        <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
            <div class="layui-form-item">
                <select name="branch" id="branchS" lay-filter="appSelect">
                    <% let is_first=true;%>
                    <% for(let k in ret.games ) {%>
                        <% if(is_first){%>
                        <option value="<%=k%>" selected><%=ret.games[k]['name']%></option>
                        <% is_first=false;%>
                        <%}else{%>
                        <option value="<%=k%>" ><%=ret.games[k]['name']%></option>
                        <%}%>
                    <%}%>
                </select> 
            </div>
            <div class="layui-form-item">
                <select name="mode" id="modeS">
                <option value="op">运营后台</option>
                <option value="dev">开发后台</option>
                </select>
            </div>
            <div class="layui-form-item">
                <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="select">确认</button>
            </div>
        </div>
    </div>


</div>
<script src="/layui/layui.js"></script>
<script>
    layui.config({
        base: '/webui/'  // 模块目录
    }).extend({
        "cosjs":"{/}/layui/?name=cosjs",
    }).use(['form','cosjs'], function () {


        let form = layui.form,cosjs=layui.cosjs,$ = layui.jquery;

        let _ret=<%-JSON.stringify(ret)%>;

    

        if(_ret.level>=100){
              window.location.href ='/main/?branch=';
              return;
        }



        if(!_ret.name){
            cosjs.alert("请重新登录");
            window.location.href="/logout/";
        }


        $(document).ready(function(){
              branchChange();
        });






   
        form.on('submit(select)', function(data){
            if($('#modeS').val()=='op')
            {
                window.location.href ='/main/?branch='+data.field.branch;
            }
            else
            {
                if(data.field.branch.length<1){
                    cosjs.alert('该app没有开发者后台');
                    return;
                }
                window.location.href =`/develop/?branch=${data.field.branch}&uid=${_ret.uid}`;
            }
            return false;
        })


        form.on('select(appSelect)', function(data){
           branchChange();
        });    

        function branchChange(){
            let _b=$('#branchS').val();
            let _html=``;
            if(_ret.op){
                if(_ret.games[_b].op)
                {
                    _html+=`
                    <option value="op">运营后台</option>
                    `
                }
            }
            if(_ret.dev){
                if(_ret.games[_b].dev)
                {
                    _html+=`
                    <option value="dev">开发后台</option>
                    `
                }
            }
            document.getElementById("modeS").innerHTML=_html;
            form.render('select');
        }

    });
</script>
</body>
</html>